package cn.com.mall.product.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.com.mall.common.utils.PageUtils;
import cn.com.mall.common.utils.Query;

import cn.com.mall.product.dao.BrandDao;
import cn.com.mall.product.entity.BrandEntity;
import cn.com.mall.product.service.BrandService;
import org.springframework.util.StringUtils;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
        if(StringUtils.isEmpty(key)){
            IPage<BrandEntity> page = this.page(
                    new Query<BrandEntity>().getPage(params),
                    new QueryWrapper<BrandEntity>()
            );
            return new PageUtils(page);
        }
        wrapper.and((item)->{
            item.like("name",key).or().like("descript",key);
        });

        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),wrapper


        );

        return new PageUtils(page);




    }

   /* @Override
    public PageUtils queryPage(Map<String, Object> params, Long brandId) {
        if(brandId==0 ){
            return queryPage(params);
        }

        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((item)->{
                item.like("name",key).or().like("descript",key);
            });
        }
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),wrapper


        );

        return new PageUtils(page);
    }*/

}